﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MemoryLoadStatistics.Models;
using MemoryLoadStatistics.Includes;

namespace MemoryLoadStatistics.Controllers
{
    public class StatController : Controller
    {
        //
        // GET: /Stat/

        /// <summary>
        /// Display some stat shit
        /// GET: /Stat/Display/{type}/{displayType}
        /// </summary>
        public ActionResult Display(string type, string displayType)
        {
            List<byte> model;
            String displayView;

            int index = 0;
            switch (type)
            {
                case RouterFragments.Type.RAM:
                    index = (int)Counter.RAM;
                    break;
                case RouterFragments.Type.CPU:
                    index = (int)Counter.CPU;
                    break;
                case RouterFragments.Type.HDD:
                    index = (int)Counter.HDD;
                    break;
                default:
                    return new HttpNotFoundResult();
            }

            switch (displayType)
            {
                case RouterFragments.Stats.MinuteStat:
                    model = DataManager.Instance.GetSeconds((Counter)index);
                    displayView = ViewNames.Minute;
                    break;

                case RouterFragments.Stats.HourlyStat:
                    model = DataManager.Instance.GetMinutes((Counter)index);
                    displayView = ViewNames.Hour;
                    break;

                case RouterFragments.Stats.DailyStat:
                    model = DataManager.Instance.GetHours((Counter)index);
                    displayView = ViewNames.Day;
                    break;

                case RouterFragments.Stats.MonthlyStat:
                    model = DataManager.Instance.GetDays((Counter)index);
                    displayView = ViewNames.Month;
                    break;

                default:
                    return new HttpNotFoundResult();
            }
            ViewBag.type = type;
            return View(displayView, null, model);

        }

        public ActionResult MixedDisplay()
        {
            List<List<byte>> mixedModel = new List<List<byte>>(DataManager.Instance.GetDaysAllCounter());
            return View("Mixed", null, mixedModel);
        }

        public ActionResult AjaxDisplay(string type, string displayType)
        {
            List<byte> model;

            int index = 0;
            switch (type)
            {
                case RouterFragments.Type.RAM:
                    index = (int)Counter.RAM;
                    break;
                case RouterFragments.Type.CPU:
                    index = (int)Counter.CPU;
                    break;
                case RouterFragments.Type.HDD:
                    index = (int)Counter.HDD;
                    break;
                default:
                    return new HttpNotFoundResult();
            }

            switch (displayType)
            {
                case RouterFragments.Stats.MinuteStat:
                    model = DataManager.Instance.GetSeconds((Counter)index);
                    break;

                case RouterFragments.Stats.HourlyStat:
                    model = DataManager.Instance.GetMinutes((Counter)index);
                    break;

                case RouterFragments.Stats.DailyStat:
                    model = DataManager.Instance.GetHours((Counter)index);
                    break;

                case RouterFragments.Stats.MonthlyStat:
                    model = DataManager.Instance.GetDays((Counter)index);
                    break;

                default:
                    return new HttpNotFoundResult();
            }

            return View("Ajax", null, model);
        }
    }
}
